var text = ActiveDoc.Text,
	eol = "\r\n";

if (text.indexOf(eol) < 0) {
	eol = text.indexOf("\n") < 0 ? "\r" : "\n";
}

var lines = text.split(eol);
text = null;
var tables = {};
var reg = /INSERT INTO `(.+)` VALUES \((.+)\);/
var k=0;
for (var i = 0, len = lines.length; i < len; i++) {
	var linei = lines[i];
	var match = reg.exec(linei);
	if(match){
		var kk = match[1];
		if(tables[kk]){
			if(i<(len-1)){
				if(lines[i+1] != ''){
					lines[i] = linei.replace('INSERT INTO `'+kk+'` VALUES ','').replace(/;$/m,',');
				}else{
					lines[i] = linei.replace('INSERT INTO `'+kk+'` VALUES ','');
				}
			}
		}else{
			tables[kk] = kk;
			if(i<(len-1)){
				if(lines[i+1] != ''){
					lines[i] = linei.replace(/;$/m,',');
				}
			}
		}
	}
}

ActiveDoc.Text = lines.join(eol) + eol;